package zajinhua;

import java.util.ArrayList;
import java.util.Arrays;

public class CardsOfPlayer {
	ArrayList<Card> myCards = new ArrayList<Card>(3);
	int value;

	public CardsOfPlayer() {
	}

	public void addCard(Card c) {
		myCards.add(c);
		System.out.println("Susess");
	}

	public int getValue() {
		int value = 0;
		this.sort();
		if (myCards.get(0).equals(myCards.get(1))
				&& myCards.get(0).equals(myCards.get(2))) {
			value = myCards.get(0).getNum() * 200000000;

		} else if (myCards.get(0).getPattern() == myCards.get(1).getPattern()
				&& myCards.get(0).getPattern() == myCards.get(2).getPattern()) {

			int v1 = myCards.get(0).getNum();
			int v2 = myCards.get(1).getNum() - 1;
			int v3 = myCards.get(2).getNum() - 2;
			if (v1 == v2 && (v2 == v3)) {
				value = v1 * 10000000;
			} else {
				value = (v1 + v2 + v3 + 3) * 100000;
			}
		} else if (myCards.get(0).getNum() == (myCards.get(1).getNum() - 1)
				&& myCards.get(0).getNum() == (myCards.get(2).getNum() - 2)) {
			value = (myCards.get(0).getNum() + myCards.get(1).getNum() + myCards
					.get(2).getNum()) * 10000;
		} else if (myCards.get(0).getPattern() == myCards.get(1).getPattern()
				|| myCards.get(0).getPattern() == myCards.get(2).getPattern()
				|| myCards.get(2).getPattern() == myCards.get(1).getPattern()) {
			if (myCards.get(0).getPattern() == myCards.get(1).getPattern()
					|| myCards.get(0).getPattern() == myCards.get(2)
							.getPattern()) {
				value = myCards.get(0).getNum() * 1000;
			} else {
				value = myCards.get(2).getNum() * 1000;
			}
		}else{
			value=myCards.get(0).getNum() + myCards.get(1).getNum() + myCards
					.get(2).getNum();
		}
        //System.out.println(value);
		return value;
	}

	public void sort() {
		Card[] cards = new Card[3];
		for (int i = 0; i < 3; i++) {
			// cards[i]=new
			// Card(myCards.get(i).getPattern(),myCards.get(i).getNum());
			cards[i] = myCards.get(i);
		}
		Arrays.sort(cards);
		for (int i = 0; i < 3; i++) {
			//System.out.println(cards[i]);
			myCards.set(i, cards[i]);
		}

	}
}
